package com.sxc.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 请求乱码，Tomcat8以上，Get请求不会乱码
 * 但是Post请求会乱码
 */
@WebServlet("/ser03")
public class Servlet03 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //设置编码
//        req.setCharacterEncoding("UTF-8");
//        // 获取客户端传递的参数
//        String username = req.getParameter("username");
//        String pwd = req.getParameter("pwd");
//        String method = req.getMethod();
//        System.out.println("请求方法为: " + method);
//        System.out.println("username: " + username);
//        System.out.println("pwd: " + pwd);
        String username = req.getParameter("username");
        System.out.println("Servlet03: " + username);

        //请求转发跳转到Servlet04
//        req.getRequestDispatcher("ser04").forward(req, resp);
        req.getRequestDispatcher("login.jsp").forward(req, resp);

    }
}
